package org.vectrics.user;

import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.vectrics.common.db.RecordObject;

public class PersonCommunication implements PersonEncounter, RecordObject {
	
	private Long id = null;
	private Person person = null;
	private Date dateStart = null;
	private Date dateEnd = null;
	private String result = null;
	private String reason = null;
	private String notes = null;
	private Set personCommunicationReasons = new HashSet();
	private String direction = null;
	private PersonCommunicationMethod method = null;
	private PersonEncounterStatusType encounterStatus = null;
	private Person leadPerson = null;
	
	public String getDescription() {
		return("Communication");
	}
	
	public String getTypeDescription() {
		return method.getPersonCommunicationMethodType().getDescriptionCode();
	}

	public Date getDateEnd() {
		return dateEnd;
	}
	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}
	public Date getDateStart() {
		return dateStart;
	}
	public void setDateStart(Date dateStart) {
		this.dateStart = dateStart;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public Person getPerson() {
		return person;
	}
	public void setPerson(Person person) {
		this.person = person;
	}
	
	public Person getLeadPerson() {
		return leadPerson;
	}

	public void setLeadPerson(Person leadPerson) {
		this.leadPerson = leadPerson;
	}
	public String getReason() {
		return reason;
	}
	public void setReason(String reason) {
		this.reason = reason;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	
	public Set getPersonCommunicationReasons() {
		return personCommunicationReasons;
	}
	
	public void setPersonCommunicationReasons(Set personCommunicationReasons) {
		this.personCommunicationReasons = personCommunicationReasons;
	}
	
	public String getDirection() {
		return direction;
	}
	
	public void setDirection(String direction) {
		this.direction = direction;
	}

	public PersonCommunicationMethod getMethod() {
		return method;
	}

	public void setMethod(PersonCommunicationMethod method) {
		this.method = method;
	}

	public PersonEncounterStatusType getEncounterStatus() {
		return encounterStatus;
	}
	public void setEncounterStatus(PersonEncounterStatusType encounterStatus) {
		this.encounterStatus = encounterStatus;
	}
	public String toString() {
		return("PersonCommunication|id=" + this.getId() + "|description" + this.getDescription());
	}
	
	public boolean hasReasonType(PersonCommunicationReasonType reasonType) {
		boolean found = false;
		
		Iterator iter = this.getPersonCommunicationReasons().iterator();
		while ((iter.hasNext()) && (found == false)) {
			PersonCommunicationReason currentReason = (PersonCommunicationReason)iter.next();
			if (currentReason.getPersonCommunicationReasonType().getCode().equals(reasonType.getCode())) {
				found = true;
			}
		}
		return(found);
	}

}
